#ifndef __DAISY_FRAME_WORK_BASE_LOGIC_FACADE_IMPL_H__
#define __DAISY_FRAME_WORK_BASE_LOGIC_FACADE_IMPL_H__

#include "FrameworkBaseConfig.h"
#include "Data.h"

#include "GameFactories.h"
#include "Theater.h"
#include <daisy\PluginsManager.h>
#include <daisy\TimerSystem.h>
#include "Builder.h"
#include <daisy\EventSystem.h>
namespace DAISY
{
namespace LogicConfiger
{



class _DaisyFrameworkBasePrivate LogicFacadeImpl
{

public:
	LogicFacadeImpl(void)
	{
	}
	~LogicFacadeImpl(void)
	{
	
	}

	bool unload(void)
	{



		_timer->stop();

		_emanager->goOut(_theater);
		_emanager->shutdown();
		

		_timer.reset();
		_theater.reset();
		_emanager.reset();


		_data.unloadPlugins();

		return true;
	}
	bool load(void)
	{

		_data.loadPlugins();


		_emanager = EventManagerPtr(new EventManager());
		_emanager->init();
		_timer = ITimerManager::getInstance().createTimer(boost::bind(&LogicFacadeImpl::update, this));
		_timer->start(WORLD_UPDATE_INTERVAL);

		
		_theater = _data.createTheater();
		

		_emanager->comeIn(_theater);

		return true;
	}
	bool building(const Builder & builder)
	{
		return builder.write(_data);
	}

	inline bool update()
	{
		_emanager->update();
		return true;
	}

private:
	
	Data _data;
	TheaterPtr _theater;
	EventManagerPtr _emanager;
	TimerPtr _timer;
	/**/
};
}

}

#endif